﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FrienDev.BusinessRules;
using FrienDev.Data;
using FrienDev.Api;
using System.Data;

public partial class Controls_Message_MessageCenter : System.Web.UI.UserControl
{    
    public int ShortMessageCount
    {
        get
        {
            return MessageRules.Instance.GetCurrentUserMessageCount();
        }
    }

    public int SystemMessageCount
    {
        get
        {
            return MessageRules.Instance.GetCurrentUserSystemMessageCount();
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (ApiHelper.Instance.IsFriendsPage())
        {
            this.pn_body.Visible = false;
        }
        else
        {
            this.rpt_MessageCenter.DataSource = MessageRules.Instance.GetCurrentUserMessagesForMessageCenter();
            this.rpt_MessageCenter.DataBind();
        }
       
        
    }
    protected void rpt_MessageCenter_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        Message message = e.Item.DataItem as Message;
        Label m_lbSendDateTime = (Label)e.Item.FindControl("lt_SendTime");
        HyperLink m_hySender = (HyperLink)e.Item.FindControl("hy_Sender");
        LinkButton m_hyMessageLink = (LinkButton)e.Item.FindControl("lbt_MessageLink");
        Label m_lblMessageId = (Label)e.Item.FindControl("lb_MessageId");       
        m_hySender.Text = UserRules.Instance.GetUserByUserId(message.SenderId).FullName;
        m_hySender.NavigateUrl = ApiHelper.Instance.GetUserHomepageLink(message.SenderId);
        m_hyMessageLink.CommandArgument = message.MessageId.ToString();
        
        
    }
    protected void rpt_MessageCenter_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "Delete")
        {
            Session["ReadMessageId"] = e.CommandArgument.ToString();
            Response.Redirect("/Home/MessageCenter.aspx");
        }
    }
}
